/*
 * @Author: your name
 * @Date: 2019-10-25 13:51:51
 * @LastEditTime: 2020-02-23 20:41:04
 * @LastEditors: nns4
 * @Description: In User Settings Edit
 * @FilePath: /note/js/12.递归.js
 */

var data = [{
    name: "全部分类",
    children: [{
            name: "衣服",
            children: [{
                    name: "男装",
                    children: [{
                        name: "背心"
                    }, {
                        name: "短裤"
                    }]
                },
                {
                    name: "女装",
                    children: [{
                        name: "连衣裙"
                    }, {
                        name: "休闲裤"
                    }]
                }
            ]
        },
        {
            name: "食品",
            children: [{
                    name: "网红零食",
                    children: [{
                        name: "拉面丸子"
                    }, {
                        name: "咪咪虾条"
                    }]
                },
                {
                    name: "糕点",
                    children: [{
                        name: "绿豆糕"
                    }, {
                        name: "手撕面包"
                    }]
                }
            ]
        }
    ]
}]



var dgdata = function () {
    var str = [];
    var dg = function (list) {
        list.forEach(function (row, index) {
            if (row.children) {
                row.type = true
                dg(row.children);
            } else {
                // str.push(row)
                row.type = true
            }
        })
    }
    dg(data);
    console.log(data);
}
dgdata() ///都写上true




// //下面使用递归来实现我们的需求  获取所有的名字
// var dgdata = function(){
//     var str = '';
//     var dg = function(list){
//         list.forEach(function(row){
//             if(row.children){
//                 dg(row.children);
//             }else{
//                 str += row.name+","
//             }
//         })
//     }
//     dg(data);
//     console.log(str);
// }



// :include="cacheList" :exclude="notCacheName"

const routes = [{
    path: '/',
    name: 'home',
}, {
    path: '/test',
    name: 'test',
    children: [{
        path: 'vuex',
        name: 'vuex',
        meta: {
            title: 'vuex示例',
            cache: true
        },

    }, {
        path: 'await',
        name: 'await',
        meta: {
            title: 'ajax等待写入vuex示例',
            cache: true
        },
    }]
}]
function tree(routes) {
    let results = [];
    find(routes)
    function find(nodes) {
        nodes.forEach(function (node) {
            if (node.name) {
                results.push(node.name);
            
            }
            if (node.children) {
                find(node.children)
            }
        });
    }
    return results;
}
console.log(tree(routes))





const routes = [{
    //首页
    path: '/',
    name: 'home',
    meta: {
        title: "首页",
        pageCache: true
    }
}, {
    //分类页
    path: '/classify',
    name: 'classify',
    meta: {
        title: "分类页"
    },
    children: [

        {
            path: '/',
            name: 'list1',
            meta: {
                title: "列表",
                pageCache: true
            },
            children: [

                {
                    path: '/',
                    name: 'list2',
                    meta: {
                        title: "列表",
                        pageCache: true
                    }
                }
            ]
        }
        
    ]
}

]

const getRouterStatus = (routers) => {
//获取隐藏地导航 和返回顶部页面名称
let hideNavs = [];
let hideBackTops = [];
let pageCache = []
find(routers)

function find(r) {
    r.forEach(function (node) {
        if (node.meta.hideNav) {
            hideNavs.push(node.name);
        }
        if (node.meta.hideBackTop) {
            hideBackTops.push(node.name);
        }

        if (node.meta.pageCache) {
            pageCache.push(node.name);
        }
        if (node.children) {
            find(node.children)
        }

    });
}
return {
    hideNavs,
    hideBackTops,
    pageCache
};
}

console.log(getRouterStatus(routes))

